#include <stdio.h>
#include <stdlib.h>
#include "list.h"

const int N = 10;

struct user {
	int id;
	struct list_head list;
};

int main(void) {
	LIST_HEAD(user_queue);

	struct user *tmp;
    struct list_head *pos;
    struct list_head *a[N];
    int i;

    for (i = 0; i < N; i++) {
        tmp = malloc(sizeof(struct user));
        //printf("Please enter user id:");
        //scanf("%d", &tmp -> id);
        tmp -> id = i+1;
        a[i] = &(tmp -> list);
        list_add_tail(a[i], &user_queue);
    }

    printf("\n");
    printf("list using list_for_each()\n");
    list_for_each(pos, &user_queue){
         tmp = list_entry(pos, struct user, list);
         printf("id= %d\n", tmp -> id);
    }

    printf("\n");
    printf("list using list_for_each_entry()\n");
    list_for_each_entry(tmp, &user_queue, list){
         printf("id= %d\n", tmp -> id);
    }

    printf("\n");
    printf("please enter a number you want to delete:\n");
    scanf("%d", &i);
    list_del(a[i-1]);
    list_for_each(pos, &user_queue){
         tmp = list_entry(pos, struct user, list);
         printf("id= %d\n", tmp -> id);
    }
    free(tmp);
    return 0;
}
